﻿<UserControl x:Class="Waf.Writer.Presentation.Views.StartView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:c="clr-namespace:Waf.Writer.Presentation.Converters"
             xmlns:p="clr-namespace:Waf.Writer.Presentation.Properties"
             xmlns:dd="clr-namespace:Waf.Writer.Presentation.DesignData"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance dd:SampleStartViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="300" d:DesignWidth="500" x:Name="startView">
    <Grid>
        <Grid.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0.5,1.5">
                <GradientStop Color="White" Offset="0" />
                <GradientStop Color="#FFECF2F9" Offset="0.662" />
                <GradientStop Color="#FFDFE9F5" Offset="1" />
            </LinearGradientBrush>
        </Grid.Background>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <Label Content="{x:Static p:Resources.StartPage}" FontSize="18" Margin="22,11,0,0"/>
        <Label Content="{x:Static p:Resources.RecentDocuments}" FontSize="14" Margin="87,11,0,0" VerticalAlignment="Bottom" Grid.Column="1"/>

        <Button x:Name="newButton" Command="{Binding FileService.NewCommand}" Width="100" Height="50" Margin="33,22,0,0" Grid.Row="1" UseLayoutRounding="True">
            <StackPanel Orientation="Horizontal">
                <Image Source="{StaticResource NewImageSource}" Width="16" Height="16"/>
                <Label Content="{x:Static p:Resources.New}" Margin="3"/>
            </StackPanel>
        </Button>

        <Button Command="{Binding FileService.OpenCommand}" Width="100" Height="50" Margin="33,22,0,0" Grid.Row="2" UseLayoutRounding="True">
            <StackPanel Orientation="Horizontal">
                <Image Source="{StaticResource OpenImageSource}" Width="16" Height="16"/>
                <Label Content="{x:Static p:Resources.Open}" Margin="3"/>
            </StackPanel>
        </Button>

        <ItemsControl ItemsSource="{Binding FileService.RecentFileList.RecentFiles}" Focusable="False" Grid.Column="1" Grid.Row="1" Grid.RowSpan="3" Margin="100,22,22,22">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <DockPanel Margin="0,0,0,15">
                        <DockPanel.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="{x:Static p:Resources.OpenFileMenu}" Click="OpenContextMenuHandler"/>
                                <MenuItem Header="{x:Static p:Resources.PinFileMenu}" Click="PinContextMenuHandler" 
                                          Visibility="{Binding IsPinned, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=Invert}"/>
                                <MenuItem Header="{x:Static p:Resources.UnpinFileMenu}" Click="UnpinContextMenuHandler"
                                          Visibility="{Binding IsPinned, Converter={StaticResource BoolToVisibilityConverter}}"/>
                                <MenuItem Header="{x:Static p:Resources.RemoveFileMenu}" Click="RemoveContextMenuHandler"/>
                            </ContextMenu>
                        </DockPanel.ContextMenu>

                        <ToggleButton IsChecked="{Binding IsPinned}" DockPanel.Dock="Left">
                            <ToggleButton.Style>
                                <Style TargetType="ToggleButton">
                                    <Setter Property="Content" Value="{StaticResource PinImage}"/>
                                    <Setter Property="ToolTip" Value="{x:Static p:Resources.PinToolTip}"/>
                                    <Style.Triggers>
                                        <Trigger Property="IsChecked" Value="True">
                                            <Setter Property="Content" Value="{StaticResource PinnedImage}"/>
                                            <Setter Property="ToolTip" Value="{x:Static p:Resources.UnpinToolTip}"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>

                        <TextBlock TextTrimming="CharacterEllipsis" Padding="11,3" ToolTip="{Binding Path}">
                            <Hyperlink Command="{Binding DataContext.FileService.OpenCommand, ElementName=startView}" CommandParameter="{Binding Path}">
                                <Run Text="{Binding Path, Converter={StaticResource MenuFileNameConverter}, Mode=OneWay}"/>
                            </Hyperlink>
                        </TextBlock>
                    </DockPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>
